/*
 *  CanvasiPhoneGL.h
 *  SypX
 *
 *  Created by Luv Khemani on 5/7/10.
 *  Copyright 2010 Luv Khemani. All rights reserved.
 *
 */

#pragma once
#ifndef SYPX_CANVASIPHONE
#define SYPX_CANVASIPHONE

#include "Canvas.h"
#include "GLView.h"
#include "Event.h"

namespace SypX
{	
	///CanvasIPhoneGL implements the canvas class for opening/creating a window/layer/context for iPhone using OpenGLES
	class SYPXAPI CanvasIPhoneGL : public Canvas
	{
	public:
		///Canvas constructor
		CanvasIPhoneGL();
		///Canvas deconstructor
		virtual ~CanvasIPhoneGL();
		///Initialise the Canvas
		virtual void init();		
		///Swaps buffers
		virtual void swapBuffers();
		///Internal method used to register Objective C classes with CanvasIPhoneGL
		static void registerWindowView(GLView* v, UIWindow* win );
		///Only on IPhone, our function pointer is static so objects in UIApplicationMain can access them
		///The reason is that we do not want to expose SypX user to Objective C classes used to handle iPhone Functionality
		//static void (*runFunctionStatic)();
		//static void (*initFunctionStatic)();
		///Returns an event from the event queue in GLView
		virtual Event getEvent();
		///Returns whether there are events queued up
		virtual bool hasEvents();		
		///Always returns true on IPhone
		virtual bool isOpen();
		///Returns the elapsed time(in seconds) since the last swapBuffer call
		virtual float getElapsedTime();
	private:
		CFTimeInterval lastTime;
		NSAutoreleasePool * pool;
		static GLView* view;
		static UIWindow* window;
		
	};
}
#endif

